home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / db / esm-3.1 / esm-3 / usr / local / sm / src / serverlib / include / timer.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-05  |  2.8 KB  |  103 lines

  1. #ifndef  _TIMER_H_
  2. #define  _TIMER_H_
  3.  
  4. /*
  5.  *   $RCSfile: timer.h,v $  
  6.  *      $Revision: 1.1.1.1 $
  7.  *   $Date: 1996/05/04 21:55:46 $
  8.  */ 
  9.  
  10. /**********************************************************************
  11. * EXODUS Database Toolkit Software
  12. * Copyright (c) 1991 Computer Sciences Department, University of
  13. *                    Wisconsin -- Madison
  14. * All Rights Reserved.
  15. *
  16. * Permission to use, copy, modify and distribute this software and its
  17. * documentation is hereby granted, provided that both the copyright
  18. * notice and this permission notice appear in all copies of the
  19. * software, derivative works or modified versions, and any portions
  20. * thereof, and that both notices appear in supporting documentation.
  21. *
  22. * THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY OF WISCONSIN --
  23. * MADISON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.  
  24. * THE DEPARTMENT DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES
  25. * WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
  26. *
  27. * The EXODUS Project Group requests users of this software to return 
  28. * any improvements or extensions that they make to:
  29. *
  30. *   EXODUS Project Group 
  31. *     c/o David J. DeWitt and Michael J. Carey
  32. *   Computer Sciences Department
  33. *   University of Wisconsin -- Madison
  34. *   Madison, WI 53706
  35. *
  36. *     or exodus@cs.wisc.edu
  37. *
  38. * In addition, the EXODUS Project Group requests that users grant the 
  39. * Computer Sciences Department rights to redistribute these changes.
  40. **********************************************************************/
  41.  
  42. /*
  43.  * similar to <sys/callout.h> but uses our list functions
  44.  */
  45. typedef struct timeval SELECTTIME;
  46. typedef long    TIME; /* the type of timeval.tv_sec from <time.h> */
  47. typedef void     *TIMERARG;
  48. typedef void     (*TIMERFUNC)( TIMERARG );
  49.  
  50. class Clock {
  51. private:
  52.     SELECTTIME    timeOfLastTick;
  53.  
  54. protected:
  55.     void   printStats();
  56.     void   clearStats();
  57. #ifdef DEBUG
  58.     void   dump( );            
  59. #endif DEBUG
  60.  
  61. public:
  62.     TIME   LastSleepTime();
  63.     TIME   Elapsed(BOOL=FALSE);    
  64. #define Reset Elapsed(TRUE)
  65. };
  66.  
  67. class Timer : public Clock {
  68.  
  69. private:
  70.     LIST    calloutList;    /* waiting to expire */
  71.     int        ncallout;        /* length of calloutList */
  72.  
  73.     LIST    expiredList;    /* expired - need to be called */
  74.     int        nexpired;
  75.  
  76.     LIST    freeList;
  77.     int        nfree;            /* length of free list */
  78.  
  79.     int        nticks, nstarted, nremoved, ncalled, nnotfound; /* clearable stats */
  80.     int        highwaterUsed;
  81.  
  82. public:
  83.     void   Init( int );            
  84.     TIME   Tick(BOOL /* force resetting the clock */, 
  85.                 BOOL /* check for expired timers  */);            
  86.     void   PrintStats();
  87.     void   ClearStats();
  88.     void   Start(TIME, TIMERFUNC, TIMERARG);            /* to start a timer */
  89.     BOOL   Remove(TIMERFUNC, TIMERARG);        /* untimeout() -- kill a timer */
  90.  
  91. #ifdef DEBUG
  92.     void   Dump( int, char * );            
  93. #endif DEBUG
  94. };
  95.  
  96. extern "C" int    gettimeofday(struct timeval*, struct timezone*);
  97.  
  98. extern Timer ServerTimer;
  99.  
  100. #define MAX_TIMERS 100
  101.  
  102. #endif _TIMER_H_
  103.